#                                               -*- Autoconf -*- 
# Process this file with autoconf to produce a configure script.

m4_define([libcanbus_version_major], [1])
m4_define([libcanbus_version_minor], [0])
m4_define([libcanbus_version_micro], [0])

m4_define([libcanbus_release_status],
          [m4_if(m4_eval(libcanbus_version_minor % 2), [1], [snapshot], [release])])

m4_define([libcanbus_version],
          [libcanbus_version_major.libcanbus_version_minor.libcanbus_version_micro])

AC_PREREQ([2.63])
AC_INIT([libcanbus], 
        [libcanbus_version], 
        [https://git.oschina.net/fulinux/libcanbus/issues],
        [libcanbus],
        [http://blog.csdn.net/fulinus])

AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([check-news foreign 1.11 -Wall -Wno-portability \
                  silent-rules tar-pax subdir-objects])

# AM_PROG_AR is not available in automake v0.11 but it's essential in v0.12.
# m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AM_PROG_AR

LT_PREREQ([2.0])
LT_INIT([dlopen])

AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/canbus.c])
AC_CONFIG_HEADERS([config.h])

# Use the silent-rules feature when possible.
m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
AM_SILENT_RULES([yes])

LIBCANBUS_VERSION_MAJOR=libcanbus_version_major
LIBCANBUS_VERSION_MINOR=libcanbus_version_minor
LIBCANBUS_VERSION_MICRO=libcanbus_version_micro
LIBCANBUS_VERSION=libcanbus_version
AC_SUBST(LIBCANBUS_VERSION_MAJOR)
AC_SUBST(LIBCANBUS_VERSION_MINOR)
AC_SUBST(LIBCANBUS_VERSION_MICRO)
AC_SUBST(LIBCANBUS_VERSION)

# Checks for programs.
#AC_PROG_CC
AC_PROG_CC_STDC
AC_PROG_INSTALL
AM_PROG_CC_C_O

# Checks for optional programs.
# AC_CHECK_PROGS([DOXYGEN], [doxygen])
# CANBUS_PROG_TRY_DOXYGEN

# Create Automake conditional based on the DOXYGEN variable
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
# AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([docs/doxygen/doxyfile])])
AS_IF([test -n "$DOXYGEN"], [AC_CONFIG_FILES([docs/doxygen/doxyfile])])

# Check whether to build docs / install man pages
AC_LIBCANBUS_CHECK_DOC_BUILD

# Checks for libraries.
# AC_SEARCH_LIBS([pthread_mutex_trylock], [pthread], [have_pthreads=yes])
# Check for pthreads
ACX_PTHREAD(
    [AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and header files.])
    LIBS="$PTHREAD_LIBS $LIBS"
    CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
    CC="$PTHREAD_CC"])

# Checks for header files.
AC_CHECK_HEADERS([stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_INT32_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T

# My CFLAGS
my_CFLAGS="-O2 -Wall -Wno-parentheses \
    -fno-strict-aliasing"
AC_SUBST([my_CFLAGS])

# Checks for library functions.
# AC_FUNC_MALLOC
AC_CHECK_FUNCS([select socket])

AC_CONFIG_FILES([Makefile
                 src/Makefile
                 src/canbus-version.h
                 docs/Makefile
                 docs/doxygen/Makefile
                 util/Makefile
                 libcanbus.pc
                 libcanbus.spec])

AC_OUTPUT

echo \
"-------------------------------------------------

${PACKAGE_NAME} Version ${PACKAGE_VERSION}

Prefix.........: ${prefix}
sysconfdir.....: ${sysconfdir}
libdir.........: ${libdir}
includedir.....: ${includedir}
Compiler.......: $CC $CFLAGS $CPPFLAGS
Linker.........: $LD $LDFLAGS $LIBS
Doxygen........: ${DOXYGEN:-NONE}
Debug Build....: $debug

Package features:

Now type 'make @<:@<target>@:>@'
where the optional <target> is:
all                - build all binaries
install            - install everything
uninstall          - uninstall everything
disclean           - clean useless everything

--------------------------------------------------"
